<#import "/spring.ftl" as spring />
<html>
<head>

	<script>
		function editInspection(code, firstName, lastName, otherPhone) {
			document.getElementById("inspectionCode").value = code;
			document.getElementById("firstName").value = firstName;
			document.getElementById("lastName").value = lastName;
			document.getElementById("otherPhone").value = otherPhone;
			document.editInspectionForm.submit();
		}
		
	</script>			
	
	<meta http-equiv="refresh" content="300" > 		
</head>
<body>

<div id="content">

	<h1>INSPECTION SNAPSHOT</h1>
	
	<p>Below you'll find a snapshot of past, present, and future inspections for ${inspectorCompany.name}...</p>
	
	<!-- MY INSPECTIONS -->
	<div class="databoxWrapper">
		<div class="databox">
			<h1>MY INSPECTIONS</h1>
	
			<div class="databoxSubLinks">
				<a href="<@spring.url "/inspector/editInspection.html" />">New Inspection</a>
			</div>
			
			<div style="text-align: right; margin-right: 20px;">sort by <a href="inspections.html?sort=date" style="font-style: italic">date</a> |  <a href="inspections.html?sort=inspector" style="font-style: italic">name</a></div>
			
			<h1>UPCOMING</h1>
			
			<table class="databoxInspectionsTable">
			<#if upcomingInspections??>
				<#list upcomingInspections as inspection>
					<#assign isCancelled = inspection.inspectionStatus == "CANCELLED" />
						
					<tr>
						<td class="databoxInspectionsTimeCell <#if isCancelled> databoxCancelledText</#if>">
							${inspection.inspectionTime?string("MMM dd")} ${inspection.inspectionTime?string("h:mma")?lower_case}
						</td>
						<td class="databoxInspectionsAddressCell <#if isCancelled>databoxCancelledText</#if>">
							<div class="databoxInspectionsInspectorTxt">${inspection.inspector.name}<#if inspection.webBooked><span class="webBooked">--web booked--</span></#if></div> 
							<div class="databoxInspectionsAddressTxt">
								${inspection.homeBuyer.name.last} - ${(inspection.property.location.street1)!}, 
								${(inspection.property.location.city)!}, ${(inspection.property.location.state)!} ${(inspection.property.location.zipCode)!}
							</div>
						</td>
						<td class="databoxInspectionsButtonsCell">
							<#if inspection.paymentTransactionId??>
						 		<a href="<@spring.url "/inspector/inspectionTransaction.html?id=${inspection.id}" />">(payment details)</a>
							</#if>
							<a href="<@spring.url "/inspector/inspection.html?id=${inspection.id}" />" class="databoxButton">VIEW</a>
							<a href="<@spring.url "/inspector/editInspection.html?id=${inspection.id}" />" class="databoxButton">EDIT</a>
						</td>
					</tr>
					<#if inspection_has_next>
						<tr>
							<td colspan="3">
								<div class="databoxInspectionsHorzLine">&nbsp;</div>
							</td>
						</tr>
					</#if>
				</#list>
			</#if>
			</table>


						
			<h1>NEEDS ATTENTION</h1>
			
			<table class="databoxInspectionsTable">
			<#if quickBookInspections??>
				<#list quickBookInspections as inspection>
					<tr>
						<td class="databoxInspectionsTimeCell">
							${inspection.inspectionTime?string("MMM dd")} ${inspection.inspectionTime?string("h:mma")?lower_case}
						</td>
						<td class="databoxInspectionsAddressCell">
							<div class="databoxInspectionsInspectorTxt">${inspection.inspector.name}<#if inspection.webBooked><span class="webBooked">--web booked--</span></#if></div>
							<div class="databoxInspectionsAddressTxt">
								${inspection.homeBuyer.name.first!} ${inspection.homeBuyer.name.last!}  (${inspection.homeBuyer.email})
							</div>
						</td>
						<td class="databoxInspectionsButtonsCell">
							<#if inspection.paymentTransactionId??>
						 		<a href="<@spring.url "/inspector/inspectionTransaction.html?id=${inspection.id}" />">(payment details)</a>
							</#if>
							<a href="<@spring.url "/inspector/inspection.html?id=${inspection.id}" />" class="databoxButton">VIEW</a>
							<a href="<@spring.url "/inspector/editInspection.html?id=${inspection.id}" />" class="databoxButton">EDIT</a>
						</td>
					</tr>
					<#if inspection_has_next>
						<tr>
							<td colspan="3"><div class="databoxInspectionsHorzLine">&nbsp;</div></td>
						</tr>
					</#if>
				</#list>
			</#if>
			</table>
			
			
						
			<h1>PAST INSPECTIONS (FROM LAST 10 DAYS)</h1>
			
			
			<#if pastInspections??>
				<div class="databoxSubtext" style="padding: 5px">NOTE: CMP=Complete, CLD=Cancelled, EXP=Auto-expired , SCD=Scheduled</div>
				
				<#-- if ordering by date, reverse order of past inspections, so latest ones show up first -->
				<#if RequestParameters.sort! != "inspector" >
					<#assign pastInspections = pastInspections?reverse />
				</#if>
				
				<table class="databoxInspectionsTable">
					<#list pastInspections as inspection>
						<tr>
							<td class="databoxInspectionsTimeCell">
								${inspection.inspectionTime?string("MMM dd")} ${inspection.inspectionTime?string("h:mma")?lower_case}<br />
								
								<span class="databoxSubtext">
								<#if inspection.inspectionStatus == "COMPLETED">
									(CMP)
								<#elseif inspection.inspectionStatus == "CANCELLED">
									(CLD)
								<#elseif inspection.inspectionStatus == "AUTO_EXPIRED">
									(EXP)
								<#elseif inspection.inspectionStatus == "SCHEDULED">
									(SCD)
								</#if>
								</span>	
							</td>
							<td class="databoxInspectionsAddressCell">
								<div class="databoxInspectionsInspectorTxt">${inspection.inspector.name}<#if inspection.webBooked><span class="webBooked">--web booked--</span></#if></div>
								<div class="databoxInspectionsAddressTxt">
									${inspection.homeBuyer.name.last} - ${(inspection.property.location.street1)!}, 
									${(inspection.property.location.city)!}, ${(inspection.property.location.state)!} ${(inspection.property.location.zipCode)!}
								</div>
							</td>
							<td class="databoxInspectionsButtonsCell">
								<#if inspection.paymentTransactionId??>
						 			<a href="<@spring.url "/inspector/inspectionTransaction.html?id=${inspection.id}" />">(payment details)</a>
								</#if>
								<a href="<@spring.url "/inspector/inspection.html?id=${inspection.id}" />" class="databoxButton">VIEW</a>
							</td>
						</tr>
						<#if inspection_has_next>
							<tr>
								<td colspan="3"><div class="databoxInspectionsHorzLine">&nbsp;</div></td>
							</tr>
						</#if>
					</#list>
				</table>
								
			<#else>
				<p class="databoxSubtext">-No inspections within the past 10 days-</p>
			</#if>
			
			<div class="databoxSubLinks">
				<a href="<@spring.url "/inspector/pastInspections.html" />">View all past inspections</a>
			</div>
							
		</div>					
	</div>
	<!-- /MY INSPECTIONS -->


	<form name="editInspectionForm" action="<@spring.url "/inspectors/${inspectorCompany.name}/editIncompleteInspection.html"/>" method="POST">
		<input type="hidden" name="inspectionCode" id="inspectionCode" value="" />
		<input type="hidden" name="homeBuyer.name.first" id="firstName" value="" />
		<input type="hidden" name="homeBuyer.name.last" id="lastName" value="" />
		<input type="hidden" name="homeBuyer.otherPhone" id="otherPhone" value="" />
	</form>

</div>

</body>
</html>
